﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using TTSBLL;
using TTSModel;

public partial class ReportingView_SendView_all : System.Web.UI.Page
{
    private  string message;
    KCCSNUnion kccsnExist;
    public ReportingView_SendView_all()
    {
        kccsnExist = new KCCSNUnion();
    }
    protected void Page_Load(object sender, EventArgs e)
    {

    }
    protected void Button1_Click(object sender, EventArgs e)
    {
        if(IsFormatChecked(TextBox_RRH.Text,out message))
        {
            if (IsBaseChecked(TextBox_RRH.Text, "请批量输入RRH的KCC号：", out  message))
            {
                if (IsFormatChecked(TextBox_DM2358.Text, out message))
                {
                    if (IsBaseChecked(TextBox_DM2358.Text, "请批量输入T0002358的KCC号：", out  message))
                     {
                         if (IsFormatChecked(TextBox_DM2046.Text, out message))
                         {
                             if (IsBaseChecked(TextBox_DM2046.Text, "请批量输入T0002046的KCC号：", out  message))
                             {
                                 this.ReportViewer1.LocalReport.ReportPath = Server.MapPath("~/ReportingView/Report4.rdlc");
                                 this.ReportViewer1.LocalReport.Refresh();
                                 this.ReportViewer1.LocalReport.DisplayName = "Shipment_Data_Traceability_BTS - R(2)";
                                 return;
                             }
                         }
                     }
                }
               
            }
           
        }
        ClientScript.RegisterStartupScript(ClientScript.GetType(), "", "<script>alert('" + message + "');</script>");
        //  this.ReportViewer1.SetDisplayMode(DisplayMode.PrintLayout);
      /*  this.ReportViewer1.LocalReport.ReportPath = Server.MapPath("~/ReportingView/Report4.rdlc");
        this.ReportViewer1.LocalReport.Refresh();
        this.ReportViewer1.LocalReport.DisplayName = "Shipment_Data_Traceability_BTS - R(2)";*/
        
    }
    protected void Button2_Click(object sender, EventArgs e)
    {
        Response.Redirect("~/ReportingView/ReportingHtml.aspx");
    }
    protected bool IsFormatChecked(string textBoxInput, out string message)
    {
        if (!string.IsNullOrEmpty(textBoxInput))
        {
            string[] textBoxArray = new string[textBoxInput.Split(',').Length];
            textBoxArray = textBoxInput.Split(',');
            for (int i = 0; i < textBoxArray.Length; i++)
            {
                if (string.IsNullOrEmpty(textBoxArray[i]))
                {
                    message = "逗号间隔之间不能有空格，并且每个输入框中不能以逗号结尾！";
                    return false;

                }
                else
                {
                    if (textBoxArray[i].Length == 12)
                    {
                        if (string.IsNullOrEmpty(kccsnExist.KCCSNUnion_GetbyKCCSN1(textBoxArray[i]).SN))
                        {
                            message = textBoxArray[i] + "在数据库中没有记录，请重新输入！";
                            return false;
                        }
                        else
                        {
                            continue;
                        }
                    }
                    else
                    {
                        message = textBoxArray[i] + "长度有问题，应为12位！";
                        return false;
                    }
                }
            }
        }     
       message = "";
       return true;
     /* for(int i=0;i<textBoxArray.Length;i++)
      {
          if(IsEmptyChecked(textBoxArray[i],out message))
          {
              if(IsLengthChecked(textBoxArray[i],out message))
              {
                  if (IsRecordChecked(textBoxArray[i], out message))
                  {
                      continue;
                  }
              }
              else
              {
                  return false;
              }

          }
          else
          {
              return false;
          }
      }
     message = "";
    return true;*/
    }
    protected bool IsBaseChecked(string textBoxInput, string lableName,out string message)
    {
        if (!string.IsNullOrEmpty(textBoxInput))
        {
            string[] textBoxArray = new string[textBoxInput.Split(',').Length];
            textBoxArray = textBoxInput.Split(',');
            for (int i = 0; i < textBoxArray.Length; i++)
            {
                if(Label1.Text==lableName)
                {
                   if( kccsnExist.KCCSNUnion_GetbyKCCSN1(textBoxArray[i]).KCCSN2.Substring(0,8)=="KCQR01AA")
                   {
                       continue;
                   }
                   else
                   {
                       message = textBoxArray[i]+"与输入框要求的KCC号不一致，请检查是否是RRH的KCC号！";
                       return false;
                   }
                }
              if (Label2.Text == lableName)
                {
                    if (kccsnExist.KCCSNUnion_GetbyKCCSN1(textBoxArray[i]).KCCSN2.Substring(0, 8) == "KCQR00AB")
                    {
                        continue;
                    }
                    else
                    {
                        message = textBoxArray[i] + "与输入框要求的KCC号不一致，请检查是否是T0002358的KCC号！";
                        return false;
                    }
                }
                if (Label3.Text == lableName)
                {
                    if (kccsnExist.KCCSNUnion_GetbyKCCSN1(textBoxArray[i]).KCCSN2.Substring(0, 8) == "KCQR00AC")
                    {
                        continue;
                    }
                    else
                    {
                        message = textBoxArray[i] + "与输入框要求的KCC号不一致，请检查是否是T0002046的KCC号！";
                        return false;
                    }
                }
            }
        }
        message = "";
        return true;
    }
     protected bool IsEmptyChecked(string textBox,out string message)
    {
        if (string.IsNullOrEmpty(textBox))
        {
            message = "逗号间隔之间不能有空格，并且每个输入框中不能以逗号结尾！";
            return false;

        }
        else
        {
            message = "";
            return true;
        }
    }
     protected bool IsRecordChecked(string textBox, out string message)
     {
         if (string.IsNullOrEmpty(kccsnExist.KCCSNUnion_GetbyKCCSN1(textBox).SN))
         {
             message = textBox + "在数据库中没有记录，请重新输入！";
             return false;

         }
         else
         {
             message = "";
             return true;
         }
     }
     protected bool IsLengthChecked(string textBox, out string message)
     {
         if (textBox.Length != 12)
         {
             message = textBox + "长度有问题，应为12位！";
             return false;

         }
         else
         {
             message = "";
             return true;
         }
     }
}